﻿using ShareFrame.IBusiness.Base_LiTest;
using ShareFrame.Entity.Base_LiTest;
using ShareFrame.Entity.DTO;
using ShareFrame.Util;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using NSwag.Annotations;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace ShareFrame.Api.Controllers.Base_LiTest
{
    /// <summary>
    /// 测试表(xiaoli)管理控制器
    /// </summary>
    [Route("/Base_LiTest/[controller]/[action]")]
    [OpenApiTag("测试表(xiaoli)管理接口", Description = "用于测试表(xiaoli)表的相关增删改查操作")]
    [ApiExplorerSettings(GroupName = "未分组接口")]
    public class Base_ProTestController : BaseApiController
    {
        #region DI

        public Base_ProTestController(IBase_ProTestBusiness base_ProTestBus, IOptions<BaseDbOption> basedbOptions)
        {
            _base_ProTestBus = base_ProTestBus;
            _basedbOptions = basedbOptions.Value;
        }

        private readonly BaseDbOption _basedbOptions;
        IBase_ProTestBusiness _base_ProTestBus { get; }

        #endregion

        #region 获取
        /// <summary>
        /// 获取实体表中全部信息
        /// </summary>
        /// <param name="input">根据传入的参数查询并分页</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<Base_ProTest>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _base_ProTestBus.GetDataListAsync(input);
        }

        /// <summary>
        /// 获取指定实体信息
        /// </summary>
        /// <param name="input">传入的指定参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Base_ProTest> GetTheData(IdInputDTO input)
        {
            return await _base_ProTestBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交
        /// <summary>
        /// 保存提交非空验证调用对应方法
        /// </summary>
        /// <param name="data">传入待操作的实体信息</param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveData(Base_ProTest data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await AddData(data);
            }
            else
            {
                await UpdateData(data);
            }
        }

        /// <summary>
        /// 基础添加方法
        /// </summary>
        /// <param name="data">待添加的实体信息</param>
        /// <returns></returns>
        [HttpPost]
        [ApiPermission("Base_ProTest.Add")]
        public async Task AddData(Base_ProTest data) 
        {
            await _base_ProTestBus.AddDataAsync(data);
        }

        /// <summary>
        /// 基础更新方法
        /// </summary>
        /// <param name="data">待更新的实体信息</param>
        /// <returns></returns>
        [HttpPost]
        [ApiPermission("Base_ProTest.Edit")]
        public async Task UpdateData(Base_ProTest data)
        {
            await _base_ProTestBus.UpdateDataAsync(data);
        }

        /// <summary>
        /// 基础删除方法
        /// </summary>
        /// <param name="ids">传入指定删除条件进行单项或多项删除</param>
        /// <returns></returns>
        [HttpPost]
        [ApiPermission("Base_ProTest.Delete")]
        public async Task DeleteData(List<string> ids)
        {
            await _base_ProTestBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}